package com.itheima.Vue.web.manager.pojo;

import java.util.List;

public class PageBean {
    //前端提供
    private Integer page;//当前页码
    private Integer count;//每页显示的数量

    //后端:数据库查寻
    private List<Contact> list;//页码联系人数
    private Integer sum; //联系人总数

    //计算得到
    private Integer first;//首页
    private Integer pre;//上页
    private Integer next;//下页
    private Integer last;//末页

    /**
     * 外部提供4个变量,内部推算其他4个,并且返回一个javaBean
     *      封装(高内聚,低耦合)
     * @param page
     * @param count
     * @param list
     * @param sum
     * @return
     */

    public static PageBean getBean(Integer page,Integer count, List<Contact> list,Integer sum){
            Integer first = 1;
            Integer pre = page - 1;
            Integer next = page + 1;
            Integer last = sum%count==0?sum/count : sum/count + 1;

        PageBean bean = new PageBean();
        bean.setPage(page);
        bean.setCount(count);
        bean.setList(list);
        bean.setSum(sum);
        bean.setFirst(first);
        bean.setPre(pre);
        bean.setNext(next);
        bean.setLast(last);
        return bean;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "page=" + page +
                ", count=" + count +
                ", list=" + list +
                ", sum=" + sum +
                ", first=" + first +
                ", pre=" + pre +
                ", next=" + next +
                ", last=" + last +
                '}';
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public List<Contact> getList() {
        return list;
    }

    public void setList(List<Contact> list) {
        this.list = list;
    }

    public Integer getSum() {
        return sum;
    }

    public void setSum(Integer sum) {
        this.sum = sum;
    }

    public Integer getFirst() {
        return first;
    }

    public void setFirst(Integer first) {
        this.first = first;
    }

    public Integer getPre() {
        return pre;
    }

    public void setPre(Integer pre) {
        this.pre = pre;
    }

    public Integer getNext() {
        return next;
    }

    public void setNext(Integer next) {
        this.next = next;
    }

    public Integer getLast() {
        return last;
    }

    public void setLast(Integer last) {
        this.last = last;
    }
}
